package Commons;

public abstract class Cell {
    protected int data = 0;
    protected int wight;

    private int mask;

    public Cell(int width) {
        this.wight = width;
        mask = 0;
        for (int i = 0; i < width; i++) {
            mask = (mask << 1) + 1;
        }
    }

    public int get() {
        return data;
    }

    public void set(int data) {
        this.data = (data & mask);
    }

    public int onlyGet(){
        return data;
    }

    public void setBit(int number, boolean value) {
        int buf = 0;
        buf = ~buf;
        buf = buf << 1;
        for (int i = 0; i < number; i++) {
            buf = (buf << 1) + 1;
        }
        data = data & buf;
        if (value) {
            buf = ~buf;
            data = data | buf;
        }
    }

    public boolean getBit(int number) {
        int buf = 1;
        buf = (buf << number);
        return ((buf & data )>0);
    }

}
